import 'package:app/pages/car_modules/car_model.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:get/get.dart';

class CarController extends GetxController{

  int page = 1;
  List dataArr = [];


  requestData({var search})async{

    var params = {
      'paeg':page,
      'limit':10,
      'search':search,
      'type':'',
    };
    var json = await DioManager().kkRequest(Address.oaCarsPage,params: params,method: 'get');

    CarModel model = CarModel.fromJson(json);

    if(page == 1){
      dataArr.clear();
      dataArr.addAll(model.data!);
    }else{
      if(model.data!= null){
        dataArr.addAll(model.data!);
      }else{
        BotToast.showText(text: '暂无更多');
      }
    }

    update();
  }
  onRefresh()async{
    page = 1 ;
    requestData();
  }
  onLoad()async{
    page++;
    requestData();
  }


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    requestData();
  }

}